package com.example;

import java.util.List;
import com.example.ref.Insert;
import com.example.ref.RSQLiteDatabase;
import com.example.ref.RSQLiteOperator;
import com.example.ref.select.Where.OrderBy;
import com.example.refdb.R;
import com.example.refdb.samples.DummyObject;


import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {


	@SuppressWarnings("unused")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		try {
			
			RSQLiteDatabase db=RSQLiteDatabase.getSingleton();
			Insert insert= db.insert( new DummyObject());
			RSQLiteDatabase.RSQLiteTransaction trans=db.beginTransaction();
			for (int i = 0; i <8000; i++) {
				trans.add(insert);
			}
			List<Object> transa=trans.executeAll(this);

			{

				List<DummyObject> listA=null;

				DummyObject dummy=new DummyObject();
				long time1,time2,time3,time4;

				time1=System.currentTimeMillis();
				listA =db.select()
						.from(DummyObject.class)
						.where("a",RSQLiteOperator.GREATER_THAN	, 100)
						//						.and("a", RSQLiteOperator.LESSER_OR_EQUALS_THAN_, 300D)
						.addOrderBy("b", OrderBy.DESCENDENT)
						.execute(this);

				time2=System.currentTimeMillis();
				Log.i("SELECT ", String.valueOf(time2-time1));
				int cnt =db.select()
						.from(DummyObject.class)
						.where("a",RSQLiteOperator.GREATER_THAN	, 100)
						//						.and("a", RSQLiteOperator.LESSER_OR_EQUALS_THAN_, 300D)
						.count(this);

				time3=System.currentTimeMillis();
				Log.i("COUNT ", String.valueOf(time3-time2));
				Log.i("count VALUE-> ",String.valueOf(cnt) );

//				if(a!=null)
//					for (DummyObject alunno : a) {
						//						Log.d("test", alunno.l);
//					}



			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}


}
